import { getWriteOffFeeInfoApi } from "@/api/financialManagement/payableManagement/paymentApproval";
import { reactive, Ref, ref } from "vue";

export default function InitHook(state: { passData: Ref<PaymentApproval.ListRows[]> }) {
  const { passData } = state;
  const formState = reactive<PaymentApproval.WriteOffFeeInfo>({
    serials: [],
    paymentApplies: []
  });
  const applyNoRef = ref<any>(null);
  const writeNoRef = ref<any>(null);
  const selectWriteNoRow = ref<any>(null);
  const loading = ref<boolean>(false);
  const init = () => {
    loading.value = true;
    return getWriteOffFeeInfoApi(passData.value.map((t: any) => t.id))
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          Object.assign(formState, data);
        }
      })
      .finally(() => (loading.value = false));
  };
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "",
    width: "",
    visible: false,
    component: "",
    type: 0
  });
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "",
    width: "",
    visible: false,
    component: "",
    type: 0
  });
  return {
    applyNoRef,
    init,
    loading,
    drawerOpts,
    dialogOpts,
    formState,
    writeNoRef,
    selectWriteNoRow
  };
}
